//
//  ResultViewController.m
//  OliveDream
//
//  Created by iOS Three on 14-9-12.
//  Copyright (c) 2014年 jiangjunli. All rights reserved.
//

#import "ResultViewController.h"
#define IS_IOS7 ([UIScreen mainScreen].bounds.size.height >= 528)
@interface ResultViewController ()

@end

@implementation ResultViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        [self.navigationItem setTitle:@"搜索结果"];
        
        UIBarButtonItem *left = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"arrow"] style:UIBarButtonItemStyleDone target:self action:@selector(buttonClick)];
        self.navigationItem.leftBarButtonItem = left;
    }
    return self;
}
-(void)buttonClick {
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    if ( [[UIDevice currentDevice].systemVersion intValue] == 7) {
        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"di"] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
    } else
        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"di.png"] forBarMetrics:UIBarMetricsDefault];
    

    // Do any additional setup after loading the view.
    _textList = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 504)];
    [_textList setBackgroundColor:[UIColor colorWithRed:0.93 green:0.92 blue:0.87 alpha:1]];
    _textList.delegate = self;
    _textList.dataSource = self;
    _textList.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_textList];
}


-(void)getContentArray:(NSMutableArray *)contentArray {
    _textArray = [[NSMutableArray alloc] init];
    _textArray = contentArray;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (_textArray != nil) {
        return _textArray.count;
    }
    return 0;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    _textCell = [tableView dequeueReusableCellWithIdentifier:@"textCell"];
    if (_textCell == nil) {
        _textCell = [[TableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
    }
    
    _textCell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    CGSize stringSize = [[_textArray objectAtIndex:indexPath.row] sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(270, 10000) lineBreakMode:NSLineBreakByTruncatingMiddle];
    float dataHeight = stringSize.height;
    
    UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(26, 10, 270, dataHeight)];
    
    contentLabel.numberOfLines = 10000;
    
    contentLabel.text = [_textArray objectAtIndex:indexPath.row];
    
    contentLabel.font = [UIFont fontWithName:@"Arial" size:15];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(15, contentLabel.frame.size.height+25, 296, 1)];
    [label setBackgroundColor:[UIColor colorWithRed:0.78 green:0.75 blue:0.69 alpha:1]];
    
    [_textCell addSubview:contentLabel];
    
    [_textCell addSubview:label];
    
    return _textCell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    CGSize stringSize = [[_textArray objectAtIndex:indexPath.row] sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(270, 10000) lineBreakMode:NSLineBreakByTruncatingMiddle];
    float dataHeight = stringSize.height;
    return dataHeight + 25;
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
